package com.kkb.servlet;

import com.alibaba.fastjson.JSONObject;
import com.kkb.pojo.ResponseData;
import com.kkb.service.GradeService;
import com.kkb.service.impl.GradeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 班级Servlet
 */
@WebServlet("/grade")
public class GradeServlet extends HttpServlet {
    private GradeService service = new GradeServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        if ("query".equals(method)) {
            query(req, resp);
        }
    }

    private void query(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        // 返回数据
        ResponseData respData = new ResponseData("gradeList",service.queryAll());
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().write(JSONObject.toJSONString(respData));
    }
}
